<template>
  <div class="app-container">
    <div class="custom_card_0">
      <el-form :model="queryParams" inline ref="queryForm" label-width="115px">
        <el-form-item label="订单编号" prop="orderNo" label-width="70px">
          <el-input v-model="queryParams.orderNo" placeholder="请输入订单编号" clearable size="small"
            @keyup.enter.native="handleQuery" />
        </el-form-item>

        <el-form-item label="员工" prop="userId">
          <el-select v-model="queryParams.userId" clearable >
            <el-option v-for="item in userList" :key="item.userId" :label="item.userName" :value="item.userId" />
          </el-select>
        </el-form-item>

        <el-form-item label="类型" prop="receiveDispatchType">
          <el-select v-model="queryParams.receiveDispatchType" placeholder="请选择" clearable>
            <el-option label="发车" :value="1" />
            <el-option label="收车" :value="2" />
          </el-select>
        </el-form-item>

        <el-form-item label="统计时间" prop="takeStartTime">
          <el-date-picker v-model="takeTime" type="daterange"
                          range-separator="至" value-format="yyyy-MM-dd" start-placeholder="开始时间" end-placeholder="结束时间"></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" size="small" icon="el-icon-search" @click="handleQuery">
            搜索
          </el-button>
          <el-button size="small" icon="el-icon-refresh" @click="resetQuery">
            重置
          </el-button>
          <el-button type="danger" icon="el-icon-refresh" @click="exportData">
            导出
          </el-button>
        </el-form-item>

      </el-form>
    </div>

    <div class="custom_card">
      <el-table ref="tables" v-loading="loading" :data="dataList" border>

        <el-table-column label="订单编号" min-width="70px" align="center" prop="orderNo">
          <template slot-scope="{row}">
            <el-button type="text" style="color: #5473e8" @click="goDetail(row.orderNo)">{{ row.orderNo }}</el-button>
          </template>
        </el-table-column>

        <el-table-column label="员工名称" min-width="70px" align="center" prop="operatorName"/>

        <el-table-column label="类型" min-width="70px" align="center" prop="receiveDispatchType"/>

        <el-table-column label="地点" min-width="70px" align="center" prop="storeName" />


        <el-table-column label="客户名称" min-width="70px" align="center" prop="memberName" />
        <el-table-column
          label="时间"
          align="center"
          min-width="130"
          show-overflow-tooltip
          prop="takeAlsoTime"
        />
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />

    </div>

  </div>
</template>

<script>
import { receiveDispatchStatistics,exportStatisticData } from "@/api/bills/performance";
import Template from "@/views/contract";
import { userlist } from '@/api/system/user'

export default {
  name: "performance",
  components: { Template },
  data() {
    return {
      // 查询参数
      queryParams: {
        carNo: null,
        illegalType: null,
        sort: null,
        order: null,
        startTime: null,
        endTime: null,
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
      dataList: [],
      userList: [],
      takeTime: [],
      // 遮罩层
      loading: true,
      //违章配置数据
      illegalSetData: {},
    }
  },
  created() {
    this.getList()
    // this.getIllegalSet()
    this.getUserList()
  },
  methods: {
    /** 获取列表数据 */
    getList() {

      if (this.takeTime) {
        this.queryParams.startTime = this.parseTime(this.takeTime[0], '{y}-{m}-{d} 00:00:00')
        this.queryParams.endTime = this.parseTime(this.takeTime[1], '{y}-{m}-{d} 23:59:59')
      }else{
        this.queryParams.startTime = null
        this.queryParams.endTime = null
      }

      this.loading = true
      receiveDispatchStatistics(this.queryParams).then(res => {
        this.dataList = res.rows
        this.total = res.total
      }).finally(() => {
        this.loading = false
      })
    },

    /** 查询用户列表 */
    getUserList() {
      userlist({}).then((response) => {
        this.userList = response.data
        console.log(this.userlist)
      })
    },

    //执行搜索
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },

    exportData(){
      const queryParams = this.queryParams
      this.$modal
        .confirm('是否确认导出数据项？')
        .then(() => {
          this.exportLoading = true
          return exportStatisticData(queryParams)
        })
        .then((response) => {
          this.$download.name(response.msg)
          this.exportLoading = false
        })
        .catch(() => {
        })
    },

    //重置搜索
    resetQuery() {
      this.queryParams = {
        carNo: null,
        illegalType: null,
        sort: null,
        order: null,
        pageNum: 1,
        pageSize: 10,
      }
      this.resetForm("queryForm")
      this.takeTime = []
      this.$refs.tables.clearSort()
      this.handleQuery()
    },

    //跳转详情
    goDetail(id) {
      this.$router.push({ name: 'OrderbasicDetail', query: { orderNo:id} })
    },

    // handleSortChange(column) {
    //   this.queryParams.sort = column.prop
    //   this.queryParams.order = column.order === 'descending' ? 'desc' : column.order === 'ascending' ? 'asc' : column.order
    //   this.getList()
    // },

  }

}
</script>

<style scoped></style>
